/*
 * DhtmlxTree.java
 *
 * Created on 2007年7月17日, 上午10:09
 *
 * 花开堪折须直折，莫待无花空折枝！
 *
 */

package com.ecomm.util;


import com.ecomm.platcore.struts.StrutsAction;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

/**
 *通过AJAX的方式请求数据 注意是传递的XML文件
 * <p>Title: 易讯聊天系统</p>
 * <p>Description:
 *  易讯聊天系统
 * </p>
 * <p>Copyright: Copyright (c) 2007</p>
 * <p>Company: 联合易讯 </p>
 * @author <font color='blue'>ppliang</font> &nbsp&nbsp<a href="mailto:pijunliang@hotmail.com">pijunliang@hotmail.com</a>
 * @version 1.0
 * @data  2007年7月17日, 上午10:09
 */
public class DhtmlxTree extends StrutsAction {
    private static final String header = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
    /** Set HTTP headers to prevent caching. */
    private final  void setNoCacheHeaders(HttpServletResponse aResponse) {
        // Set to expire far in the past.
        aResponse.setHeader("Expires", "Sat, 6 May 1995 12:00:00 GMT");
        
        // Set standard HTTP/1.1 no-cache headers.
        aResponse.setHeader("Cache-Control", "no-store, no-cache, must-revalidate");
        
        // Set IE extended HTTP/1.1 no-cache headers (use addHeader).
        aResponse.addHeader("Cache-Control", "post-check=0, pre-check=0");
        
        // Set standard HTTP/1.0 no-cache header.
        aResponse.setHeader("Pragma", "no-cache");
        //注意这里是XML的方式
        aResponse.setContentType("text/xml;charset=UTF-8");
        
        aResponse.setCharacterEncoding("UTF-8");
        
    }
    
    /**
     *列出所有的人员和部门，
     */
    public ActionForward getOrgmodleUserXml(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response) {
        PrintWriter out;
        String id = (String)request.getParameter("id");
        String userid = (String)request.getParameter("userid");
        try {
            this.setNoCacheHeaders(response);
            out = response.getWriter();
            String content = new com.ecomm.util.FunctionDhtmlxTreeMng().dumpSelectUsere(id,userid);
            System.out.println("countent==="+content);
            out.print(content);//ajax取得都是字符的输出。如果数据量大的话，还可以用xml来发送和接受
            if (out != null) {
                out.flush();
                out.close();
                out = null;
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return null;
    }
    /**
     *列出所有的人员和部门，
     */
    public ActionForward getChatUser(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response) {
        PrintWriter out;
        String id = (String)request.getParameter("id");
        try {
            this.setNoCacheHeaders(response);
            out = response.getWriter();
            String content = new com.ecomm.util.FunctionDhtmlxTreeMng().dumpSelectUsere(id);
            System.out.println("countent==="+content);
            out.print(content);//ajax取得都是字符的输出。如果数据量大的话，还可以用xml来发送和接受
            if (out != null) {
                out.flush();
                out.close();
                out = null;
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return null;
    }
}
